package com.manger.common.tcp.server;

import com.manger.common.tcp.server.handle.TcpServerHandler;
import com.manger.common.tcp.server.handle.TcpServerHeartBeatHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.bytes.ByteArrayDecoder;
import io.netty.handler.codec.bytes.ByteArrayEncoder;
import io.netty.handler.timeout.IdleStateHandler;

import java.util.concurrent.TimeUnit;

public class TcpServerChannel extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ch.pipeline().addLast("idle",new IdleStateHandler(7, 5, 0,
                TimeUnit.SECONDS));
        ch.pipeline().addLast(
                new ByteArrayDecoder(),
                new ByteArrayEncoder()
        );

        ch.pipeline().addLast(new TcpServerHandler());

        ch.pipeline().addLast("myIdle",new TcpServerHeartBeatHandler());

    }
}
